package com.example.demo.tools;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override  //增添时自动填充
    public void insertFill(MetaObject metaObject) {
        log.info("公共字段填充中");
        metaObject.setValue("createDate", LocalDateTime.now());
        metaObject.setValue("updateDate", LocalDateTime.now());
    }

    @Override//修改时执行
    public void updateFill(MetaObject metaObject) {
        log.info("公共字段填充中");
        metaObject.setValue("updateDate", LocalDateTime.now());
    }
}
